﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.Model;

namespace WXYW
{
    public partial class QWXZQSearch : System.Web.UI.Page
    {
        public QWXZQStationModel StationModel = new QWXZQStationModel();
        public QWXYWPersonModel PersonModel = new QWXYWPersonModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int startYear = 2010; startYear <= DateTime.Now.Year; startYear++)
                {
                    YearDDL.Items.Add(new ListItem(startYear.ToString(), startYear.ToString()));
                }

                for (int month = 1; month <= 12; month++)
                {
                    MonthDDL.Items.Add(new ListItem(month.ToString(), month.ToString()));
                }

                YearDDL.SelectedValue = DateTime.Now.Year.ToString();
                MonthDDL.SelectedValue = DateTime.Now.Month.ToString();

                ServiceStationService stationService = new ServiceStationService();
                StationDDL.DataSource = stationService.GetAllWithSelectOne();                
                StationDDL.DataTextField = "Name";
                StationDDL.DataValueField = "ID";
                StationDDL.DataBind();

                PersonDDL.Items.Add(new ListItem("请选择人员", "0"));
            }
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            QWXZQService service = new QWXZQService();
            if (PersonDDL.SelectedValue.Equals("0") && !StationDDL.SelectedValue.Equals("0"))
            {
                StationModel = service.GetQWXZQStationSummaryInfo(Convert.ToInt32(StationDDL.SelectedValue),
                    Convert.ToInt32(YearDDL.SelectedValue), Convert.ToInt32(MonthDDL.SelectedValue));
                ResultMultiView.ActiveViewIndex = 0;
            }
            else if (PersonDDL.SelectedValue.Equals("0") && StationDDL.SelectedValue.Equals("0"))
            {
                ResultMultiView.ActiveViewIndex = 2;
            }
            else if (!PersonDDL.SelectedValue.Equals("0") && !StationDDL.SelectedValue.Equals("0"))
            {
                PersonModel = service.GetQWXZQPersonModel(Convert.ToInt32(PersonDDL.SelectedValue),
                     Convert.ToInt32(YearDDL.SelectedValue), Convert.ToInt32(MonthDDL.SelectedValue));
                ResultMultiView.ActiveViewIndex = 1;
            }
        }

        protected void StationDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!StationDDL.SelectedValue.Equals("0"))
            {
                UserService userService = new UserService();
                PersonDDL.DataSource = userService.GetUserOfStation(Convert.ToInt32(StationDDL.SelectedValue));
                PersonDDL.DataTextField = "UserName";
                PersonDDL.DataValueField = "UserID";
                PersonDDL.DataBind();
            }
            else
            {
                PersonDDL.Items.Clear();
                PersonDDL.Items.Add(new ListItem("请选择人员", "0"));
            }
            ResultMultiView.ActiveViewIndex = 2;
        }
    }
}
